﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PedestrianSensingRadar
{
    /// <summary>
    /// 描述：检测区域类
    /// </summary>
    public abstract class CheckArea
    {
        public Point p1, p4;
        public byte areaNum;//区域编号
        public int cout = 0;//区域数量
        ////public int[] existflag = new int[2];//区域是否存在编号
        private Pen drawPen = new Pen(Color.Red, 2);

        public PictureBox mPictureBox;//字段
        public Rectangle rect;
        public bool allowDeformingDuringMovement = false;


        private int sizeNodeRect = 8;//矩形8个边角矩形的大小

        public PosSizableRect nodeSelected = PosSizableRect.None;

        public enum PosSizableRect
        {
            UpMiddle,//上中小方块
            LeftMiddle,//左中小方块
            LeftBottom,//左下小方块
            LeftUp,//左上方块
            RightUp,
            RightMiddle,
            RightBottom,
            BottomMiddle,
            None
        };//八个小矩形

        public CheckArea(Rectangle r)//构造方法
        {
            rect = r;
        }

        public abstract void Draw(Graphics gra);

     
       
        public Rectangle CreateRectSizableNode(int x, int y)
        {
            return new Rectangle(x - sizeNodeRect / 2, y - sizeNodeRect / 2, sizeNodeRect, sizeNodeRect);
        }//创建标签矩形

        public Rectangle GetRect(PosSizableRect p)//缩放功能相关
        {
            switch (p)
            {

                case PosSizableRect.LeftUp:
                    return CreateRectSizableNode(rect.X, rect.Y);

                case PosSizableRect.LeftMiddle:
                    return CreateRectSizableNode(rect.X, rect.Y + rect.Height / 2);

                case PosSizableRect.LeftBottom:
                    return CreateRectSizableNode(rect.X, rect.Y + rect.Height);

                case PosSizableRect.BottomMiddle:
                    return CreateRectSizableNode(rect.X + rect.Width / 2, rect.Y + rect.Height);

                case PosSizableRect.RightUp:
                    return CreateRectSizableNode(rect.X + rect.Width, rect.Y);

                case PosSizableRect.RightBottom:
                    return CreateRectSizableNode(rect.X + rect.Width, rect.Y + rect.Height);

                case PosSizableRect.RightMiddle:
                    return CreateRectSizableNode(rect.X + rect.Width, rect.Y + rect.Height / 2);

                case PosSizableRect.UpMiddle:
                    return CreateRectSizableNode(rect.X + rect.Width / 2, rect.Y);

                default:
                    return new Rectangle();

            }

        }

        public PosSizableRect GetNodeSelectable(Point p)
        {
            foreach (PosSizableRect r in Enum.GetValues(typeof(PosSizableRect)))
            {

                if (GetRect(r).Contains(p))//如果鼠标在小矩形内
                {
                    nodeSelected = r;
                    return r;//返回这个矩形
                }

            }
            nodeSelected = PosSizableRect.None;
            return PosSizableRect.None;//否则返回null
        }

        public void ChangeCursor(Point p)
        {
            mPictureBox.Cursor = GetCursor(GetNodeSelectable(p));
        }

        /// <summary>
        /// Get cursor for the handle
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public Cursor GetCursor(PosSizableRect p)
        {
            switch (p)
            {

                case PosSizableRect.LeftUp:
                    return Cursors.SizeNWSE;

                case PosSizableRect.LeftMiddle:
                    return Cursors.SizeWE;

                case PosSizableRect.LeftBottom:
                    return Cursors.SizeNESW;

                case PosSizableRect.BottomMiddle:
                    return Cursors.SizeNS;

                case PosSizableRect.RightUp:
                    return Cursors.SizeNESW;

                case PosSizableRect.RightBottom:
                    return Cursors.SizeNWSE;

                case PosSizableRect.RightMiddle:
                    return Cursors.SizeWE;

                case PosSizableRect.UpMiddle:
                    return Cursors.SizeNS;

                default:
                    return Cursors.Default;
            }
        }
    }
}

